(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.glSystem.viewController', viewController);
	viewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'glSystemService' ];
	function viewController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, glSystemService) {
		var ctrl = this, glSystemInfo = $scope.$stateParams.params;
		ctrl.glSystem = {};
		glSystemService.initPageCallback(ctrl);
		ctrl.init = function() {
			var params = {
					glSystem : glSystemInfo.glSystem,
				};
			glSystemService.getGlSystemLayout('view').then(function(layoutRsponse) {
				if (!layoutRsponse.data) {
					return;
				}
				ctrl.layoutConfig = layoutRsponse.data;
				glSystemService.loadOptions().then(function(glSystemOptions) {
					var glSystem;
					glSystemService.initOptions(ctrl, glSystemOptions);
					authService.view(params).then(function(response) {
						glSystem = response.data;
						if (glSystem) {
							ctrl.glSystem = glSystem;
				    	}
					});
				});
			});
		};
	}
})(angular);